﻿3033.修改矩阵
/**
 * Return an array of arrays of size *returnSize.
 * The sizes of the arrays are returned as *returnColumnSizes array.
 * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
 */
    int** modifiedMatrix(int** matrix, int matrixSize, int* matrixColSize, int* returnSize, int** returnColumnSizes) {
    int** ans = (int**)malloc(sizeof(int*) * matrixSize);
    for (int i = 0; i < matrixSize; i++)
    {
        ans[i] = (int*)malloc(sizeof(int) * (*matrixColSize));
        memcpy(ans[i], matrix[i], (*matrixColSize) * 4);
    }


    for (int i = 0; i < matrixSize; i++)
    {
        for (int j = 0; j < (*matrixColSize); j++)
        {
            if (ans[i][j] == -1)
            {
                int max = 0;
                for (int k = 0; k < matrixSize; k++)
                {
                    if (ans[k][j] > max)
                    {
                        max = ans[k][j];
                    }
                }
                ans[i][j] = max;;
            }
        }
    }
    *returnSize = matrixSize;
    *returnColumnSizes = matrixColSize;
    return ans;
}

506.相对名词
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
    char** findRelativeRanks(int* score, int scoreSize, int* returnSize) {
    char** ans = (char**)malloc(sizeof(char*) * scoreSize);
    for (int i = 0; i < scoreSize; i++)
    {
        int count = scoreSize;
        for (int j = 0; j < scoreSize; j++)
        {
            if (score[i] > score[j])
            {
                count--;
            }
        }

        char* temp = (char*)malloc(sizeof(char) * 12);
        if (count == 1)
        {
            temp = "Gold Medal\0";
        }
        else if (count == 2)
        {
            temp = "Silver Medal\0";
        }
        else if (count == 3)
        {
            temp = "Bronze Medal\0";
        }
        else
        {
            sprintf(temp, "%d", count);
        }
        ans[i] = temp;
    }
    *returnSize = scoreSize;
    return ans;
}

509.斐波那契数
int fib(int n) {
    if (n == 1)
    {
        return 1;
    }
    int first = 0, second = 1, ans = 0;
    for (int i = 1; i < n; i++)
    {
        ans = first + second;
        first = second;
        second = ans;
    }
    return ans;
}

520.检测大写字母
bool detectCapitalUse(char* word) {
    int count = 0;
    for (int i = 0; i < strlen(word); i++)
    {
        if (word[i] >= 'A' && word[i] <= 'Z')
        {
            count++;
        }
    }

    if (count == strlen(word) || (count == 1 && (word[0] >= 'A' && word[0] <= 'Z')) || count == 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

521.最长特殊序列-I
int findLUSlength(char* a, char* b) {
    if (strlen(a) < strlen(b))
    {
        return strlen(b);
    }
    else if (strlen(a) > strlen(b))
    {
        return strlen(a);
    }
    else
    {
        if (strcmp(a, b) == 0)
        {
            return -1;
        }
        else
        {
            return strlen(a);
        }
    }
}